home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / inter52g.zip / INT2QH.ZIP / INT2QH2.C < prev    next >
C/C++ Source or Header  |  1994-04-23  |  6KB  |  318 lines

  1. /* INT2QH.C
  2.  *
  3.  * Author:   Kai Uwe Rommel
  4.  * Date:     Sun 07-Oct-1990
  5.  * Update:   Sat 20-Oct-1990
  6.  * Update:   Sun 11-Nov-1990 Ralf Brown
  7.  * Update:             Ralf Brown (added Bent Lynggaard's INT2GUID enh)
  8.  * Update:   Sat 23-Apr-1994 Ralf Brown (updated for compat. w/ INTER41)
  9.  *
  10.  * Compiler: MS C 5.00 and newer / compact model, or TC 2.0 / compact model
  11.  * System:   PC/MS-DOS 3.20 and newer, OS/2 1.0 and newer
  12.  *
  13.  */
  14.  
  15. #define LABEL    "int2qh.c"
  16. #define VERSION  "1.4"
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22.  
  23. #define divider_line(s) (strncmp(s,"--------",8)==0)
  24.  
  25.  
  26. FILE *input, *output, *topics, *subtopics;
  27.  
  28. char line1[128];
  29. char line2[128];
  30. char category[128];
  31. char parent[128];
  32.  
  33. char infilename[14] = "interrup.lst";
  34. #define infileExt 9
  35. int splitInfile = 0;
  36.  
  37. int sub;
  38.  
  39.  
  40. void diskFull(void)
  41. {
  42.   fputs("\n\nDisk full\n", stderr);
  43.   fcloseall();
  44.  
  45.   unlink("topic.tmp");
  46.   unlink("subtopic.tmp");
  47.   exit(1);
  48. }
  49.  
  50. int _fputs(char *line, FILE *stream)
  51. {
  52.   char buffer[128];
  53.   int cnt = 0;
  54.  
  55.   while ( *line )
  56.   {
  57.     if ( *line == '\\' )
  58.       buffer[cnt++] = '\\';
  59.  
  60.     buffer[cnt++] = *line++;
  61.   }
  62.  
  63.   buffer[cnt] = 0;
  64.  
  65.   return fputs(buffer, stream);
  66. }
  67.  
  68. char *_fgets(char *s, int n, FILE *stream)
  69. {
  70.   char *ptr;
  71.   ptr = fgets(s, n, stream);
  72.   if ( (ptr==NULL) && (stream==input) && splitInfile )
  73.   {
  74.     fclose(input);
  75.     infilename[infileExt]++;
  76.     input = fopen(infilename, "r");
  77.     if ( input != NULL )
  78.     {
  79.       fprintf(stderr, "%s\n", infilename);
  80.       ptr = fgets(s, n, input);
  81.     }
  82.   }
  83.   return ptr;
  84. } /* _fgets */
  85.  
  86. void Initialize(void)
  87. {
  88.   input     = fopen(infilename, "r");
  89.   if ( input == NULL )
  90.   {
  91.     infilename[infileExt] = 'a';
  92.     infilename[infileExt+1] = 0;
  93.     input = fopen(infilename, "r");
  94.     if ( input == NULL )
  95.     {
  96.       fputs("Cannot open input file (INTERRUP.LST or INTERRUP.A)\n", stderr);
  97.       exit(1);
  98.     }
  99.     splitInfile = 1;
  100.   }
  101. #ifdef __MSDOS__
  102.   setvbuf(input,NULL,_IOFBF,8192) ;
  103. #endif
  104.   fprintf(stderr, "%s\n", infilename);
  105.   output    = stdout;
  106.   topics    = fopen("topic.tmp", "w");
  107.   subtopics = fopen("subtopic.tmp", "w");
  108.  
  109.   fprintf(topics,
  110.     ".context List Categories\n.list\nInterrupt-List\n"
  111.     ".context Interrupt-List\n.context INTLIST\n.topic Interrupt-List\n.list\n"
  112.     );
  113. }
  114.  
  115.  
  116. void Cleanup(void)
  117. {
  118.   fclose(topics);
  119.   fclose(subtopics);
  120.   fputs("Cleaning up\n", stderr);
  121.  
  122.   topics = fopen("topic.tmp", "r");
  123.   subtopics = fopen("subtopic.tmp", "r");
  124.  
  125.   while ( fgets(line1, sizeof(line1), topics) )
  126.     if ( fputs(line1, output) == EOF )
  127.       diskFull();
  128.  
  129.   while ( fgets(line1, sizeof(line1), subtopics) )
  130.     if ( fputs(line1, output) == EOF )
  131.       diskFull();
  132.  
  133.   fcloseall();
  134.  
  135.   unlink("topic.tmp");
  136.   unlink("subtopic.tmp");
  137. }
  138.  
  139.  
  140. void CopyFile(char *name)
  141. {
  142.   FILE *temp = fopen(name, "r");
  143.  
  144.   if ( temp == NULL )
  145.   {
  146.     fprintf(stderr, "WARNING: Could not open %s\n", name);
  147.     fputs("Information was not available\n", output);
  148.   }
  149.   else
  150.   {
  151.     while ( fgets(line2, sizeof(line2), temp) )
  152.       _fputs(line2, output);
  153.  
  154.     fclose(temp);
  155.   }
  156. }
  157.  
  158.  
  159. void StartTopic(char *name, char *desc)
  160. {
  161.   fprintf(sub ? subtopics : topics, "%s  %s\n", name, desc);
  162.   fprintf(output, ".context %s\n.category %s\n.topic %s\n", name, parent, desc);
  163. }
  164.  
  165.  
  166. void StartList(char *name, char *desc)
  167. {
  168.   fprintf(topics, "%s  %s (list)\n", name, desc);
  169.   fprintf(subtopics, ".context %s\n.category %s\n.topic %s\n.list\n", name, parent, desc);
  170.  
  171.   strcpy(category, desc);
  172.   strcpy(parent, name);
  173.   sub = 1;
  174. }
  175.  
  176.  
  177. void EndList(void)
  178. {
  179.   strcpy(category, "Interrupt-List");
  180.   strcpy(parent, "INTLIST");
  181.   sub = 0;
  182. }
  183.  
  184.  
  185. char *NextID(void)
  186. {
  187.   static char ID[32];
  188.   static unsigned long CurrentID = 0;
  189.  
  190.   CurrentID++;
  191.   sprintf(ID, "IL%04ld", CurrentID);
  192.  
  193.   return ID;
  194. }
  195.  
  196.  
  197. int RecognizedTopic(void)
  198. {
  199.   char *ptr, topic[64], desc[128];
  200.  
  201.   if ( _fgets(line2, sizeof(line2), input) == NULL )
  202.     return 0;
  203.  
  204.   if (strncmp("INT ",line1,4) != 0)
  205.     return 0;
  206.  
  207.   ptr = line1 + 6 ;
  208.   while (*ptr == ' ')
  209.      ptr++ ;
  210.   *--ptr = 0;
  211.   strcpy(topic, line1);
  212.   *ptr = ' ';
  213.  
  214.   if ( topic[strlen(topic) - 1] == 'h' )
  215.     topic[strlen(topic) - 1] = 0;
  216.  
  217.   if ( strcmp(category, topic) && sub )
  218.     EndList();
  219.  
  220.   strcpy(desc, line1);
  221.   desc[strlen(desc) - 1] = 0;
  222.  
  223.   for (ptr = line2 ; isspace(*ptr) ; ptr++)
  224.      ;
  225.  
  226.   if ( (!strncmp(ptr, "AX =", 4) ||
  227.     !strncmp(ptr, "AH =", 4) ||
  228.     !strncmp(ptr, "AL =", 4))
  229.        && !sub )
  230.     StartList(NextID(), topic);
  231.  
  232.   StartTopic(NextID(), desc);
  233.  
  234.   _fputs(line1, output);
  235.   if ( !divider_line(line2) )
  236.     _fputs(line2, output);
  237.  
  238.   return 1;
  239. }
  240.  
  241.  
  242. void CopyTopic(void)
  243. {
  244.   if ( divider_line(line2) )
  245.   { /* kludge for one-line interrupts */
  246.     _fgets(line1, sizeof(line2), input);
  247.     return;
  248.   }
  249.  
  250.   for (;;)
  251.   {
  252.     if ( _fgets(line1, sizeof(line1), input) == NULL )
  253.       break;
  254.  
  255.     if ( !divider_line(line1) )
  256.       _fputs(line1, output);
  257.     else
  258.     {
  259.       if ( _fgets(line2, sizeof(line2), input) == NULL )
  260.     break;
  261.  
  262.       if ( strncmp(line2, "INT ", 4) )
  263.       {
  264.     _fputs(line1, output);
  265.     _fputs(line2, output);
  266.       }
  267.       else
  268.       {
  269.     strcpy(line1, line2);
  270.     break;
  271.       }
  272.     }
  273.   }
  274. }
  275.  
  276.  
  277. void main(void)
  278. {
  279.   fprintf(stderr, "\nINT2QH %s - (c) Kai Uwe Rommel/Bent Lynggaard - %s\n", VERSION, __DATE__);
  280.  
  281.   Initialize();
  282.   EndList();
  283.  
  284.   StartTopic("HEADER", "Overview of the Interrupt List");
  285.   CopyTopic();
  286.  
  287.   StartTopic("MEMLIST", "BIOS Memory List");
  288.   CopyFile("memory.lst");
  289.  
  290.   StartTopic("PORTS", "I/O Ports") ;
  291.   CopyFile("ports.lst") ;
  292.  
  293.   StartTopic("CMOS", "CMOS Memory Locations") ;
  294.   CopyFile("cmos.lst") ;
  295.  
  296.   StartTopic("CPUBUGS", "Bugs in various CPUs") ;
  297.   CopyFile("86bugs.lst") ;
  298.  
  299.   StartTopic("Primer  ", "What is an interrupt?");
  300.   CopyFile("interrup.pri") ;
  301.  
  302.   StartTopic("Glossary", "Terminology used in the List") ;
  303.   CopyFile("glossary.lst") ;
  304.  
  305.   StartTopic("INTERRUP.1ST","How to get/update the Interrupt List");
  306.   CopyFile("interrup.1st") ;
  307.  
  308.   while ( RecognizedTopic() )
  309.     CopyTopic();
  310.  
  311.   Cleanup();
  312.  
  313.   exit(0);
  314. }
  315.  
  316.  
  317. /* End of INT2QH.C */
  318.